package core;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;

import Panel.MyPanel;

public class main3 {

	static JFrame okno;
	static ArrayList<JButton> buttons = new ArrayList<JButton>();
	static Iterator<JButton> iButtons;
	static JButton b;
	static JPanel content;
	
	static Border border = BorderFactory.createLineBorder(Color.black);
	
	public static void main(String[] args) {

		okno = new JFrame("Nauka Javy");
		JPanel menu = new JPanel();
		content = new JPanel();
		
		okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		ActionListener actionListener = new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				switch (e.getActionCommand()) {
				case "Kania":
					MyPanel.setKaniaPanel(content);			break;
				case "Pasqal":
					MyPanel.setPasqalPanel(content);		break;
				case "Layouty":
					MyPanel.setLayoutPanel(content);		break;
				case "Pliki":
					MyPanel.setFilesPanel(content);			break;
				case "Wyjątki":
					MyPanel.setExceptionsPanel(content);	break;
				case "A kysz!":
					System.exit(0);							break;
				}
				okno.pack();
			}
		};

		buttons.add(new JButton("Kania"));
		buttons.add(new JButton("Pasqal"));
		buttons.add(new JButton("Layouty"));
		buttons.add(new JButton("Pliki"));
		buttons.add(new JButton("Wyjątki"));
		buttons.add(new JButton("A kysz!"));
		
		iButtons = buttons.iterator();
		
		while (iButtons.hasNext()) {
			b = (JButton) iButtons.next();
			b.addActionListener(actionListener);
			menu.add(b);
		}
		
		menu.setLayout( new FlowLayout() );
		content.setLayout( new GridLayout() );
		content.setBorder(border);
		
		okno.add(menu, BorderLayout.NORTH);
		okno.add(content, BorderLayout.CENTER);
		
		okno.pack();
		okno.setVisible(true);

	}
}
